/*else*/
var stateElse = "pending";
var uploaderElse;
var listElse =[];
$(document).ready(function(){
//	$('#myModal').on('hide.bs.modal', function () {
//		uploaderShareHolder.destroy();
//	});
//	$("#myModal").on("shown.bs.modal",function(){
		uploaderElse = WebUploader.create({
			swf : "./third-party/webuploader/Uploader.swf",
			server : "/test/uploadtest",
			auto : true,
			pick : {
				id:"#else",
				multiple :false
			},fileNumLimit: 1,
			accept :{
				extensions: 'gif,jpg,jpeg,bmp,png'
			},
			resize : false
		});
		uploaderElse.on("fileQueued",function(file){
			$("#fileInfo6").append('<div id="'+file.id+'" ><div style="background:url(./third-party/webuploader/upload-file.jpg);height:20px;width:23px;float:left;margin-left:40px;"></div>'+file.name+'<a href="javascript:removeListElse('+file.id+')" style="padding-left:10px;">删除</a></div>');
			$("#filename").textbox('setValue', file.name);
		});

		uploaderElse.on("uploadAccept",function(object,ret ){
			for(var i=0;i<ret.length;i++){
				listElse.push({"url":ret[i].url,"filename":ret[i].filename});
				}
		});
		uploaderElse.on("uploadProgress",function(file,percentage){
			var fileId = $("#"+file.id),
			percent = fileId.find(".progress .progress-bar");
			if(!percent.length){//避免重复创建
				percent = $('<div class="progress progress-striped active"><div class="progress-bar" role="progressbar" style="width: 0%"></div></div>')
				.appendTo(fileId).find('.progress-bar');
			}
			fileId.find('p.state').text('上传中');
			percent.css( 'width', percentage * 100 + '%' );
		});
		uploaderElse.on( 'uploadSuccess', function( file ) {
			debugger;
			//alert(listElse[0].url);
			$('#photo').val(listElse[0].url);
			document.getElementById("yulan").src='http://localhost:8080'+listElse[0].url;
			//$("#yulan").attr("src","http://localhost:8080"+listElse[0].url);
			$( '#'+file.id ).find('p.state').text('已上传');
		});

		uploaderElse.on( 'uploadError', function( file ) {
			$( '#'+file.id ).find('p.state').text('上传出错');
			alert("网络异常，上传图片失败！");
		});

		uploaderElse.on( 'uploadComplete', function( file) {
			$( '#'+file.id ).find('.progress').fadeOut();

		});
		uploaderElse.on( 'all', function( type ) {
			if ( type === 'startUpload' ) {
				stateElse = 'uploading';
			} else if ( type === 'stopUpload' ) {
				stateElse = 'paused';
			} else if ( type === 'uploadFinished' ) {

				stateElse = 'done';
			}
			if ( stateElse === 'uploading' ) {
				$("#start").text('提交......');
			} else {
				$("#start").text('提交');
			}
		});
		uploaderElse.on( "uploadError", function( obj, reason  ) {
			var errorMessage = obj.message;
			alert(errorMessage,3); 
		});
	});
//});
/*移除上传列表*/
function removeListElse(obj,fname){
	var filename;
	if(uploaderElse.getFile(obj.id)){
		filename = uploaderElse.getFile(obj.id).name;
		uploaderElse.removeFile(uploaderElse.getFile(obj.id));
	}else{
		filename = 	fname;
	}
	listElse.removeElseListFile(listElse,filename);
	$(obj).remove();
}
Array.prototype.removeElseListFile = function(_arr,_obj){
	var len = _arr.length;
	for(var i = 0; i < len; i++)
	{
		if(_arr[i].filename == _obj)
		{
			this.splice(i, 1);
			return parseInt(i);
		}
	}
	return -1;
};